<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/7/15
 * Time: 11:11
 */
namespace app\admin\controller;
use think\Db;
use think\Request;
class Feedback extends Base {
    public function index(){
        if(request()->isAjax()){
            extract(input());
            $map =array();
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
            if(isset($keyword)&&$keyword!="")
            {
                $map['a.feedback_id'] = ['like',"%" . $keyword . "%"];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end=="")
            {
                $map['a.feedback_time'] = ['>= time',$start];
            }
            if(isset($end)&&$end!=""&&isset($start)&&$start=="")
            {
                $map['a.feedback_time'] = ['<= time',$end];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end!="")
            {
                $map['a.feedback_time'] = ['between time',[$start,$end]];
            }
            if(isset($status)&&$status!="")
            {
                $map['a.feedback_status'] = $status;
            }
            $count = Db::table('up_feedback')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.f_user_id','left')
                ->where($map)
                ->count();
            $list = Db::table('up_feedback')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.f_user_id','left')
                ->where($map)
                ->field('a.*,uuu.user_username,uuu.user_phone')
                ->order('a.feedback_status asc,a.feedback_time desc')
                ->page($page, $limit)
                ->select();//计算总页面
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$list]);
        }
        return $this->fetch();
    }


    /**
     * 标记已处理
     * @return \think\response\Json
     */
    public function handle(){
        $yy_id = input('id');
        $res = Db::table('up_feedback')
            ->where('feedback_id', $yy_id)
            ->update(['feedback_status' => 2]);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    public function del(){
        $id = input('param.id');
        $res = Db::table('up_feedback')->where('feedback_id',$id)->delete();
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
}